package com.sjm.suchbear.minibookmall.manage;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sjm.suchbear.minibookmall.BookDB;
import com.sjm.suchbear.minibookmall.R;
import com.sjm.suchbear.minibookmall.Utils.T;
import com.sjm.suchbear.minibookmall.action.NoticeManage;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AddNoticeActivity extends Activity {

    @BindView(R.id.ll_header_back)
    LinearLayout llHeaderBack;
    @BindView(R.id.tv_list_title)
    TextView tvListTitle;
    @BindView(R.id.iv_header_function_ico)
    ImageView ivHeaderFunctionIco;
    @BindView(R.id.ll_header_function)
    LinearLayout llHeaderFunction;
    @BindView(R.id.ll_List_Main)
    RelativeLayout llListMain;
    @BindView(R.id.et_noticeTitle)
    EditText etNoticeTitle;
    @BindView(R.id.et_noticeContent)
    EditText etNoticeContent;
    @BindView(R.id.tv_addNotice)
    TextView tvAddNotice;

    private String noticeTitle;
    private String noticeContent;
    private SQLiteDatabase dbread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_notice);
        ButterKnife.bind(this);
        BookDB db = new BookDB(getBaseContext());
        dbread = db.getReadableDatabase();
        tvListTitle.setText("新增公告");
    }


    @OnClick({R.id.ll_header_back, R.id.tv_addNotice})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_header_back:
                finish();
                break;
            case R.id.tv_addNotice:
                addNotice();
                break;
        }
    }

    private void addNotice() {
        noticeTitle = etNoticeTitle.getText().toString();
        noticeContent = etNoticeContent.getText().toString();
        if (noticeTitle.equals("")) {
            T.showShort(getBaseContext(), "请输入标题");
            return;
        }
        if (noticeContent.equals("")) {
            T.showShort(getBaseContext(), "请输入内容");
            return;
        }
        NoticeManage.addNotice(dbread, noticeTitle, noticeContent);
        T.showShort(getBaseContext(), "添加成功");
        finish();
    }
}
